<?php

/**
 * md5模式匹配，不区分大小写。
 * @param string $str 待匹配的MD5字符串
 */
function isMd5Format($str){
	$regex = '/^[a-zA-Z0-9]{16}$/';
	if(preg_match($regex, $str)){
		return true;
	}else{
		return false;
	}
}

function randomDigital($len=6){
	return randomString(6,'0123456789');
}

function randomString($len=8,$ranSet=null){
	if($ranSet == null){
		$chars='0123456789abcdefghijklmnopqrstuvwxyz';
	}else{
		$chars = $ranSet;
	}
	mt_srand(microtime() * 1000000 * getmypid());
	
	$res='';
	while(strlen($res) < $len){
		$res.=substr($chars, mt_rand() % (strlen($chars)-1), 1);
	}
	return $res;
}
function addslashes4array($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = addslashes4array($val);
		}
	} else {
		$string = addslashes($string);
	}
	return $string;
}

